import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class InputTest extends JPanel {
        private Point player;
		private Keys[] test;
		private final double SPEED = 8;
        private double xmov = 0, ymov = 0;


        public InputTest() {
                player = new Point(403, 314);
				KeyInput keyreader = new KeyInput(this);

                test = new Keys[2];
                test[0] = Keys.ERROR;
                test[1] = Keys.ERROR;

                Timer t = new Timer(30, new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							repaint();
						}
					});


				t.start();

        }
        public void update(Keys[] k) {
                test = k;
				if (k[0] == Keys.UP) {
							ymov = -SPEED;
							xmov = 0;
				} else if (k[0] == Keys.DOWN) {
							ymov = SPEED;
							xmov = 0;
				} else if (k[0] == Keys.LEFT) {
							xmov =-SPEED;
							ymov = 0;
				} else if (k[0] == Keys.RIGHT) {
							xmov = SPEED;
							ymov = 0;
				} else if (k[0] == Keys.D_DL) {
							xmov = -SPEED / Math.sqrt(2);
							ymov = SPEED / Math.sqrt(2);
				} else if (k[0] == Keys.D_UL) {
							xmov = -SPEED / Math.sqrt(2);
							ymov = -SPEED / Math.sqrt(2);
				} else if (k[0] == Keys.D_UR) {
							xmov = SPEED / Math.sqrt(2);
							ymov = -SPEED / Math.sqrt(2);
				} else if (k[0] == Keys.D_DR) {
							xmov = SPEED / Math.sqrt(2);
							ymov = SPEED / Math.sqrt(2);
				} else {
							xmov = 0;
							ymov = 0;
				}
                repaint();
        }

        public void paintComponent(Graphics g) {
				super.paintComponent(g);
				g.setColor(Color.black);
			    g.drawString("test1: " + test[0] + " test2: " + test[1], 50, 50);

				g.setColor(Color.red);
                player.setLocation(player.getX() + xmov, player.getY() + ymov);
                g.fillRect((int)Math.rint(player.getX()), (int)Math.rint(player.getY()), 20, 20);

        }
        public static void main(String[] args) {
                SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                                createAndShowGUI();
                        }
                });
        }
        public static void createAndShowGUI() {
                JFrame w = new JFrame("Test");
                w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                w.setSize(806, 628);
                w.setLocationRelativeTo(null);
                w.setResizable(false);
                w.setVisible(true);
                InputTest input = new InputTest();
                w.add(input);
                input.requestFocus();
        }
}